<div class="x_panel">
  <div class="x_content row">
    <div class="col-xs-12">
      <form class="form-horizontal form-label-left" action="{$actionUrl}" method="post" enctype="multipart/form-data">
        <div class="form-group">
          <label class="control-label col-md-2 col-sm-4 col-xs-12">商城名称：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class="form-control col-md-3 col-xs-12" required="required" type="text" name="form[mall_name]" value="{$mall.mall_name}">
          </div>

          <label class="control-label col-md-2 col-sm-4 col-xs-12">合作商：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <select required="required" class="form-control" name="form[partner_id]">
              {foreach $partner AS $key => $value}
              <option value="{$value.partner_id}" {if ($mall.partner_id==$value.partner_id)}selected{/if}>{$value.partner_name}</option>
              {/foreach}
            </select>
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">状态：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class=""  type="radio" name="form[mall_status]" value="1" {if ($mall.mall_status==1)}checked="checked"{/if}>是
            <input class=""  type="radio" name="form[mall_status]" value="0" {if ($mall.mall_status==0)}checked="checked"{/if}>否
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">商城LOGO：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-12 com-xs-12">
            {if $mall_logo}<img style="width:100px;height:100px;" src="{$mall_logo}"/>{/if}
            <input type="file" name="mall_logo">
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">商城风格：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class=""  type="radio" name="form[mall_style]" value="0" {if ($mall.mall_status==0)}checked="checked"{/if}>列表
            <input class=""  type="radio" name="form[mall_style]" value="1" {if ($mall.mall_status==1)}checked="checked"{/if}>一行2列
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">首页广告图：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-12 com-xs-12">
            {if $adv_pic}<img style="width:100px;height:100px;" src="{$adv_pic}"/>{/if}
            <input type="file" name="adv_pic">
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">首页广告链接：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class="form-control col-md-3 col-xs-12" type="text" name="form[adv_link]" value="{$mall.adv_link}">
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">主题色：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class="form-control col-md-3 col-xs-12" required="required" type="text" name="form[mall_color]" value="{$mall.mall_color}">
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">隐藏标题栏：<b style="color:red">*</b></label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            <input class="" required="required" type="checkbox" name="form[hide_title]" value="1" {if ($mall.hide_title==1)}checked="checked"{/if}>
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">订单数量：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            {$mall.order_num}
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">商品数量：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            {$mall.goods_num}
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">商品数量：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            {$mall.goods_num}
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">创建时间：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            {$mall.add_time}
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">修改时间：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            {$mall.update_time}
          </div>
          <label class="control-label col-md-2 col-sm-4 col-xs-12">访问链接：</label>
          <div class="checkbox col-md-10 col-sm-8 col-xs-12">
            {$mall.mall_link}
          </div>



        </div>
        <div class="col-md-3 col-sm-12 col-xs-12 col-md-offset-4 col-sm-offset-4">
          <input name="mall_id" type="hidden" value="{$mall.mall_id}">
          <button class="btn btn-primary" type="submit">更新</button>
        </div>
      </form>
    </div>
  </div>
</div>

<div class="x_panel">
  <div class="x_content" style="display: block;">
    <div class="nav navbar-right panel_toolbox">
      <!--<a class="fa fa-plus" href="/mall/add-mall-goods.html?mall_id={$mall.mall_id}">添加商品</a>-->
      <button id="add-goods" class="btn btn-primary btn-xs" data="{$mall.mall_id}"> 添加商品</button>
    </div>
    <br><br>
    <!--表格主体内容-->
    <div class="cont">
      <table class="table table-bordered table-striped">
        <thead>
        <tr>
          <th>商品ID</th>
          <th>商品原价</th>
          <th>商品销售价</th>
          <th>商品图片</th>
          <th>商品名称</th>
          <th>商品分类</th>
          <th>商品描述</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $mall_goods.lists as $goodsitem}
        <tr>
          <td>{$goodsitem.goods_id}</td>
          <td>{$goodsitem.market_price}</td>
          <td>{$goodsitem.real_price}</td>
          <td><img src="{$goodsitem.goods_listpic}" width="50px" height="50px" /> </td>
          <td>{$goodsitem.goods_name}</td>
          <td>{$goodsitem.category_name}</td>
          <td width="200px">{$goodsitem.goods_summary}</td>
          <td>{$goodsitem.goods_status}</td>
          <td>
            <div class="x_content">
              <button class="edit-sort btn btn-primary btn-xs" data-sort="{$goodsitem.sort}" data-mall="{$mall.mall_id}" data-goods="{$goodsitem.goods_id}"> 调整排序</button>
              <button class="btn btn-danger btn-xs" data-toggle="dropdown">删除
                <i class="icon-angle-down"></i></button>
              <ul class="dropdown-menu">
                <li><a href="{eval U(['mall/delete-goods','goods_id'=>$goodsitem.goods_id,'mall_id'=>$mall.mall_id])}">确定</a></li>
                <li><a href="javascript:;">取消</a></li>
              </ul>
            </div>
          </td>
        </tr>
        {/foreach}
        </tbody>
      </table>
      <!--分页-->
      {Yii::$app->view->render('/com/pager.php',['pager'=>$mall_goods.pager])}
    </div>
  </div>
</div>


<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel">添加商品</h4>
      </div>
      <div class="modal-body">
        <div class="loaders">
          <div class="ball-spin-fade-loader">
              <select id="goodssel" class="form-control" name="form[goods_id]">
                <option value="0">请选择</option>
              </select>
          </div>
        </div>
        <div id="modal-dyn"></div>
      </div>
      <div class="modal-footer" style="border:none;">
        <button id="addgoods" type="button" class="copy btn btn-secondary" data="{$mall.mall_id}">提交</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal1">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel1">排序调整为</h4>
      </div>
      <div class="modal-body">
        <div class="loaders">
          <div class="ball-spin-fade-loader">
            <input id="goodssort" type="text" value="" />位
          </div>
        </div>
        <div id="modal-dyn1"></div>
      </div>
      <div class="modal-footer" style="border:none;">
        <button id="sortgoods" type="button" class="copy btn btn-secondary" data-mall="" data-goods="">提交</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>

<script>
    $("#add-goods").click(function () {
        var mall_id = $(this).attr('data');
        var url = "{['mall/get-goods']|U}";
        $.post(url, 'mall_id='+mall_id, function (data) {
            $.each(data, function(i, item){
                html = '<option value="'+item.goods_id+'">'+item.goods_name+'</option>'
                $('#goodssel').append(html);
            });

        },'json');

        //var data = $(this).attr("data");
        //$("#link").val(data);
        $('#detail-modal').modal('show');
    })

    $(".edit-sort").click(function () {
        $('#sortgoods').attr('data-mall',$(this).attr('data-mall'));
        $('#sortgoods').attr('data-goods',$(this).attr('data-goods'));
        $('#goodssort').val($(this).attr('data-sort'));
        $('#detail-modal1').modal('show');
    })

    $("#addgoods").click(function () {
        var mall_id = $(this).attr('data');
        var goods_id = $('#goodssel').val();
        if(goods_id==0)
            return false;
        var url = "{['mall/add-goods']|U}";
        $.post(url, 'mall_id='+mall_id+'&goods_id='+goods_id, function (data) {
            window.location.reload();
        },'json');

        //var data = $(this).attr("data");
        //$("#link").val(data);
        $('#detail-modal').modal('hide');
    })

    $("#sortgoods").click(function () {
        var mall_id = $(this).attr('data-mall');
        var goods_id = $(this).attr('data-goods');
        var sort = $('#goodssort').val();
        if(!sort)
            sort = 0;
        var url = "{['mall/sort-goods']|U}";
        $.post(url, 'mall_id='+mall_id+'&goods_id='+goods_id+'&sort='+sort, function (data) {
            window.location.reload();
        },'json');
        $('#detail-modal').modal('hide');
    })

</script>

